<?php
namespace app\index\controller;
use think\Controller;
use think\Loader;
class  Login extends  Controller{

    //注册发送验证码
    public function registerCode(){
        $phone          = trim(input('phone'));
        $graph_code     = trim(input('graph_code'));
        $invoking       = Loader::model('Login','service');
        $response       = $invoking->commonCodeApi($phone,$graph_code,1);
        return json($response);
    }

    //注册
    public function userRegister(){
        $input = input();
        $parr['phone']      = trim($input['phone']);
        $parr['graph_code'] = trim($input['graph_code']);
        $parr['phone_code'] = trim($input['verification_code']);
        $parr['password']   = trim($input['password']);
        $invoking       = Loader::model('Login','service');
        $response       = $invoking->userRegisterApi($parr);
        return json($response);
    }

    //用户登录
    public function userLog(){
        $input = input();
        $parr['number']     = trim($input['number']);
        $parr['password']   = trim($input['password']);
        $invoking           = Loader::model('Login','service');
        $response           = $invoking->userLogApi($parr);
        return json($response);
    }


    //忘记密码 发送短信验证
    public function forgetCode(){
        $phone          = trim(input('phone'));
        $graph_code     = trim(input('graph_code'));
        $invoking       = Loader::model('Login','service');
        $response       = $invoking->commonCodeApi($phone,$graph_code,2);
        return json($response);
    }

    //忘记密码-重置密码
    public function forgetSetPassword(){
        $input = input();
        $parr['phone']      = trim($input['phone']);
        $parr['graph_code'] = trim($input['graph_code']);
        $parr['phone_code'] = trim($input['verification_code']);
        $parr['password']   = trim($input['password']);
        /*$parr['verify_password']   = trim($input['verify_password']);*/
        $invoking       = Loader::model('Login','service');
        $response       = $invoking->forgetSetPasswordApi($parr);
        return json($response);
    }


    //下载文书
    public function docDownload(){
        $writ_id = input('writ_id');
        $invoking       = Loader::model('Login','service');
        $invoking->docDownloadApi($writ_id);
    }

    //退出登录
    public function userQuit(){
        $user       = session('lt_user');
        if(empty($user)){
            $response = messageInfo ( '101', '你已退出登录,请勿重复操作！' );
            return json($response);
        }
        session('lt_user',null);
        $response = messageInfo ( '202', '退出成功！' );
        return json($response);
    }

}
